﻿using EV.EventBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZoneLine.ViewModels;

namespace ZoneLine.Views
{
    /// <summary>
    /// InventoryView.xaml 的交互逻辑
    /// </summary>
    public partial class InventoryView : Window
    {
        public InventoryView()
        {
            InitializeComponent();
            this.Loaded += InventoryView_Loaded;
            this.Closed += InventoryView_Closed;
        }

        private void InventoryView_Loaded(object sender, RoutedEventArgs e)
        {
            MessageCenter.Subscribe(nameof(InventoryView), Guid.NewGuid().ToString(), (s) =>
            {
                if (s.Source.Payload is string ss)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        var viewModel = this.DataContext as InventoryViewModel;
                        if (viewModel != null)
                        {
                            viewModel.InventoryInfo.MainBatchCode = ss;
                        }
                    });
                }
                return Task.CompletedTask;
            });
        }

        private void InventoryView_Closed(object sender, EventArgs e)
        {
            MessageCenter.Unsubscribe(nameof(InventoryView));
        }

    }
}
